﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace ProjectSheduleAnalyst
{
    public partial class MainForm : Form
    {
        private LessonsList leslist = new LessonsList(); //не забывай об этой строке
        private DB_Access dba = new DB_Access();
        
        private int rowIndex;
        private int colIndex;
        private int flag; // 1 = RightButton, 2 = LeftButton, 3 = Show Limitation
        public string classroom;
        private bool enterfl; // для контроля DragEnter

        public MainForm()
        {
           InitializeComponent();

           //Карех, обрати внимание, как вызывается для использования лист с занятиями
           leslist.LessonsToList();     //создание листа с исчерпывающей информацией (14 параметров)
           leslist.SmLesLisCreation();   //урезанный(для тебя)
            

            //Ричтекстбокс просто показывает как в твоем малеником листе обстоят дела
            for (int i = 0; i < leslist.LessList.Count; i++)
            {
                richTextBox1.Text += leslist.SmallLessonList[i]+Environment.NewLine;
            }

            //Еще есть табпейдж называемый test (никуда его не девай пока что)
            //там на дэйтагридвью полностью показано, что находится в большом листе
            //Будь здоров!)
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            
            dataGridView1.DataSource = leslist.tbl_lessons;

            //ЗАГРУЗКА ПРЕПОДАВАТЕЛЕЙ
            DataSet ds1 = dba.FillGrid("SelectAllTeachers", "Teachers");
            dgvTeachers.DataSource = ds1.Tables["Teachers"].DefaultView;
            dgvTeachers.Columns[0].Visible = false;

            dgvTeachers.Columns[1].HeaderText = "Фамилия";
            dgvTeachers.Columns[2].HeaderText = "Имя";
            dgvTeachers.Columns[3].HeaderText = "Отчество";
            dgvTeachers.Columns[4].HeaderText = "Кафедра";

            //ЗАГРУЗКА ГРУПП
            DataSet ds2 = dba.FillGrid("SelectAllGroups", "Groups");
            dgvGroups.DataSource = ds2.Tables["Groups"].DefaultView;
            dgvGroups.Columns[0].Visible = false;

            dgvGroups.Columns[1].HeaderText = "Курс";
            dgvGroups.Columns[2].HeaderText = "Специальность";
            dgvGroups.Columns[3].HeaderText = "Группа";
            dgvGroups.Columns[4].HeaderText = "Подгруппа";

            //ЗАГРУЗКА ПРЕДМЕТОВ
            DataSet ds3 = dba.FillGrid("SelectAllSubjects", "Subjects");
            dgvSubjects.DataSource = ds3.Tables["Subjects"].DefaultView;
            dgvSubjects.Columns[0].Visible = false;

            dgvSubjects.Columns[1].HeaderText = "Название предмета";

            //ЗАГРУЗКА ТИПОВ АУДИТОРИЙ
            DataSet ds4 = dba.FillGrid("SelectAllClassRoomTypes", "ClassRoomTypes");
            dgvClassroomType.DataSource = ds4.Tables["ClassRoomTypes"].DefaultView;
            dgvClassroomType.Columns[0].Visible = false;

            dgvClassroomType.Columns[1].HeaderText = "Тип";

            //ЗАГРУЗКА АУДИТОРИЙ
            DataSet ds5 = dba.FillGrid("SelectAllClassRooms", "ClassRooms");
            dgvClassrooms.DataSource = ds5.Tables["ClassRooms"].DefaultView;
            dgvClassrooms.Columns[0].Visible = false;

            dgvClassrooms.Columns[1].HeaderText = "Номер";
            dgvClassrooms.Columns[2].HeaderText = "Тип";

            ///
            
            int temp, cls;

            for (int j = 0; j < 18; j++)
            {
                ScheduleDGV.Rows.Add();
                for (int i = 0; i < 7; i++)
                {
                    switch (j)
                    {
                        case 0:
                            ScheduleDGV.Rows[j].Cells[0].Value = "Понедельник";
                            break;

                        case 6:
                            ScheduleDGV.Rows[j].Cells[0].Value = "Вторник";
                            break;
                        case 12:
                            ScheduleDGV.Rows[j].Cells[0].Value = "Среда";
                            break;
                        default:
                            ScheduleDGV.Rows[j].Cells[0].Value = "               " + "\n" + "                 ";
                            break;
                    }
                }

             
            }

            for (int i = 0; i < leslist.LessList.Count; i++)
            {
                LeftDGV.Rows.Add();
                LeftDGV.Rows[i].Cells[0].Value = leslist.SmallLessonList[i].ToString();
            }

            toolTip1.SetToolTip(label1, "Аудитории не назначены. Для выбора аудитории воспользуйтесь кнопкой 'информация' или перетащите занятие левой кнопкой мыши занятие в расписание.");

            ScheduleDGV.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
            ScheduleDGV.RowTemplate.DefaultCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;

            ScheduleDGV.RowHeadersVisible = false;

        }



        private void AddTeacherButton_Click(object sender, EventArgs e)
        {
            AddChangeTeachersForm AddTeacher = new AddChangeTeachersForm();
            AddTeacher.Text = "Добавление нового преподавателя";
            AddTeacher.AddChangeTacherBtn.Text = "Добавить";
            //AddTeacher.Show();

            if (AddTeacher.ShowDialog() == DialogResult.OK)
              {
                  dba.MySQLquery(@"INSERT INTO TEACHERS (SURNAME, NAME, PATRONYMIC, DEPARTMENT) VALUES
                    ('" + AddTeacher.SurnameTextBox.Text + "','" 
                        + AddTeacher.NameTextBox.Text + "','" 
                        + AddTeacher.PatronymicTextBox.Text + "','" 
                        + AddTeacher.DepartmentTextBox.Text + "')");

                  DataSet ds1 = dba.FillGrid("SelectAllTeachers", "Teachers");
                  dgvTeachers.DataSource = ds1.Tables["Teachers"].DefaultView;
              }
        }

        private void ChangeTeacherButton_Click(object sender, EventArgs e)
        {
            AddChangeTeachersForm ChngTeacher = new AddChangeTeachersForm();
            ChngTeacher.Text = "Изменение данных о преподавателе";
            ChngTeacher.AddChangeTacherBtn.Text = "Изменить";
            ChngTeacher.SurnameTextBox.Text = dgvTeachers.CurrentRow.Cells[1].Value.ToString();
            ChngTeacher.NameTextBox.Text = dgvTeachers.CurrentRow.Cells[2].Value.ToString();
            ChngTeacher.PatronymicTextBox.Text = dgvTeachers.CurrentRow.Cells[3].Value.ToString();
            ChngTeacher.DepartmentTextBox.Text = dgvTeachers.CurrentRow.Cells[4].Value.ToString();
            //ChngTeacher.Show();

            if (ChngTeacher.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"UPDATE TEACHERS
                SET SURNAME = '" + ChngTeacher.SurnameTextBox.Text + "', NAME = '" 
                                 + ChngTeacher.NameTextBox.Text + "', PATRONYMIC = '" 
                                 + ChngTeacher.PatronymicTextBox.Text + "', DEPARTMENT = '" 
                                 + ChngTeacher.DepartmentTextBox.Text + "' WHERE ID ='"
                                 + dgvTeachers.CurrentRow.Cells[0].Value.ToString() +"' ");

                DataSet ds1 = dba.FillGrid("SelectAllTeachers", "Teachers");
                dgvTeachers.DataSource = ds1.Tables["Teachers"].DefaultView;
            }
        }

        private void DeleteTeacherButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранного преподавателя?", "Предупреждение!", 
                    MessageBoxButtons.OKCancel,MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM TEACHERS WHERE ID='" 
                    + dgvTeachers.CurrentRow.Cells[0].Value.ToString() + "'");
            }

            DataSet ds1 = dba.FillGrid("SelectAllTeachers", "Teachers");
            dgvTeachers.DataSource = ds1.Tables["Teachers"].DefaultView;
        }

        private void AddGroupButton_Click(object sender, EventArgs e)
        {
            AddChangeGroupsForm AddGroup = new AddChangeGroupsForm();
            AddGroup.Text = "Добавление новой группы";
            AddGroup.AddChangeGroupBtn.Text = "Добавить";
            //AddGroup.Show();

            if (AddGroup.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"INSERT INTO GROUPS (CourseNumber, Speciality, GroupNumber, SubGroup) VALUES
                    ('" + AddGroup.CourseTextBox.Text + "','"
                      + AddGroup.SpecialityTextBox.Text + "','"
                      + AddGroup.GroupTextBox.Text + "','"
                      + AddGroup.SubgroupTextBox.Text + "')");

                DataSet ds2 = dba.FillGrid("SelectAllGroups", "Groups");
                dgvGroups.DataSource = ds2.Tables["Groups"].DefaultView;
            }
        }

        private void ChangeGroupButton_Click(object sender, EventArgs e)
        {
            AddChangeGroupsForm ChngGroup = new AddChangeGroupsForm();
            ChngGroup.Text = "Изменение данных о группе";
            ChngGroup.AddChangeGroupBtn.Text = "Изменить";
            ChngGroup.CourseTextBox.Text = dgvGroups.CurrentRow.Cells[1].Value.ToString();
            ChngGroup.SpecialityTextBox.Text = dgvGroups.CurrentRow.Cells[2].Value.ToString();
            ChngGroup.GroupTextBox.Text = dgvGroups.CurrentRow.Cells[3].Value.ToString();
            ChngGroup.SubgroupTextBox.Text = dgvGroups.CurrentRow.Cells[4].Value.ToString();

            //ChngGroup.Show();

            if (ChngGroup.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"UPDATE GROUPS
                SET CourseNumber = '" + ChngGroup.CourseTextBox.Text + "', Speciality = '"
                                 + ChngGroup.SpecialityTextBox.Text + "', GroupNumber = '"
                                 + ChngGroup.GroupTextBox.Text + "', SubGroup = '"
                                 + ChngGroup.SubgroupTextBox.Text + "' WHERE ID ='"
                                 + dgvGroups.CurrentRow.Cells[0].Value.ToString() + "' ");

                DataSet ds2 = dba.FillGrid("SelectAllGroups", "Groups");
                dgvGroups.DataSource = ds2.Tables["Groups"].DefaultView;
            }
        }

        private void DeleteGroupButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранную группу?", "Предупреждение!",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM GROUPS WHERE ID='"
                    + dgvGroups.CurrentRow.Cells[0].Value.ToString() + "'");
            }

            DataSet ds2 = dba.FillGrid("SelectAllGroups", "Groups");
            dgvGroups.DataSource = ds2.Tables["Groups"].DefaultView;
        }

        private void AddSubjectButton_Click(object sender, EventArgs e)
        {
            AddChangeSubjectsForm AddSubject = new AddChangeSubjectsForm();
            AddSubject.Text = "Добавление нового предмета";
            AddSubject.AddChangeSubjectBtn.Text = "Добавить";

            if (AddSubject.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"INSERT INTO SUBJECTS (Name) VALUES
                    ('" + AddSubject.SubjectNameTextBox.Text + "')");

                DataSet ds3 = dba.FillGrid("SelectAllSubjects", "Subjects");
                dgvSubjects.DataSource = ds3.Tables["Subjects"].DefaultView;
            }
        }

        private void ChangeSubjectButton_Click(object sender, EventArgs e)
        {
            AddChangeSubjectsForm ChngSubject = new AddChangeSubjectsForm();
            ChngSubject.Text = "Изменение данных о предмете";
            ChngSubject.AddChangeSubjectBtn.Text = "Изменить";
            ChngSubject.SubjectNameTextBox.Text = dgvSubjects.CurrentRow.Cells[1].Value.ToString();


            if (ChngSubject.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"UPDATE SUBJECTS
                SET NAME = '" + ChngSubject.SubjectNameTextBox.Text + "' WHERE ID ='"
                                 + dgvSubjects.CurrentRow.Cells[0].Value.ToString() + "' ");

                DataSet ds3 = dba.FillGrid("SelectAllSubjects", "Subjects");
                dgvSubjects.DataSource = ds3.Tables["Subjects"].DefaultView;
            }
        }

        private void DeleteSubjectButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранный предмет?", "Предупреждение!",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM SUBJECTS WHERE ID='"
                    + dgvSubjects.CurrentRow.Cells[0].Value.ToString() + "'");
            }

            DataSet ds3 = dba.FillGrid("SelectAllSubjects", "Subjects");
            dgvSubjects.DataSource = ds3.Tables["Subjects"].DefaultView;
        }

        private void AddClassTypeButton_Click(object sender, EventArgs e)
        {
            AddChangeClassroomTypesForm AddClassroomType = new AddChangeClassroomTypesForm();
            AddClassroomType.Text = "Добавление нового типа аудиторий";
            AddClassroomType.AddChangeCLRTypeBtn.Text = "Добавить";

            if (AddClassroomType.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"INSERT INTO CLASSROOMTYPES (Name) VALUES
                    ('" + AddClassroomType.ClassroomTypeTextBox.Text + "')");

                DataSet ds4 = dba.FillGrid("SelectAllClassRoomTypes", "ClassRoomTypes");
                dgvClassroomType.DataSource = ds4.Tables["ClassRoomTypes"].DefaultView;
            }
        }

        private void ChangeClassTypeButton_Click(object sender, EventArgs e)
        {
            AddChangeClassroomTypesForm ChngClassroomType = new AddChangeClassroomTypesForm();
            ChngClassroomType.Text = "Изменение типа аудитории";
            ChngClassroomType.AddChangeCLRTypeBtn.Text = "Изменить";
            ChngClassroomType.ClassroomTypeTextBox.Text = dgvClassroomType.CurrentRow.Cells[1].Value.ToString();


            if (ChngClassroomType.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"UPDATE CLASSROOMTYPES
                SET NAME = '" + ChngClassroomType.ClassroomTypeTextBox.Text + "' WHERE ID ='"
                                 + dgvClassroomType.CurrentRow.Cells[0].Value.ToString() + "' ");

                DataSet ds4 = dba.FillGrid("SelectAllClassRoomTypes", "ClassRoomTypes");
                dgvClassroomType.DataSource = ds4.Tables["ClassRoomTypes"].DefaultView;
            }
        }

        private void DeleteClassTypeButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранный тип аудитории?", "Предупреждение!",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM CLASSROOMTYPES WHERE ID='"
                    + dgvClassroomType.CurrentRow.Cells[0].Value.ToString() + "'");
            }

            DataSet ds4 = dba.FillGrid("SelectAllClassRoomTypes", "ClassRoomTypes");
            dgvClassroomType.DataSource = ds4.Tables["ClassRoomTypes"].DefaultView;
        }

        public void AddClassroomButton_Click(object sender, EventArgs e)
        {
            AddChangeClassroomForm AddClass = new AddChangeClassroomForm();
            AddClass.Text = "Добавление новой аудитории";
            AddClass.AddChangeClassroomBtn.Text = "Добавить";

            if (AddClass.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"INSERT INTO CLASSROOMS (Number, CTYPE) VALUES
                    ('" + AddClass.ClassNumberTextBox.Text + "','"
                      + AddClass.idlist[AddClass.ClassTypeComboBox.SelectedIndex]  + "')");

                DataSet ds5 = dba.FillGrid("SelectAllClassRooms", "ClassRooms");
                dgvClassrooms.DataSource = ds5.Tables["ClassRooms"].DefaultView;
            }
        }

        public void ChangeClassroomButton_Click(object sender, EventArgs e)
        {
            AddChangeClassroomForm ChngClass = new AddChangeClassroomForm();
            ChngClass.Text = "Изменение данных об аудитории";
            ChngClass.AddChangeClassroomBtn.Text = "Изменить";

            ChngClass.ClassNumberTextBox.Text = dgvClassrooms.CurrentRow.Cells[1].Value.ToString();
            
            //ChngClass.ClassTypeComboBox.SelectedIndex = 
            //есть помарочка с индексами когда во время работы добавляем новые типы аудиторий
            
            if (ChngClass.ShowDialog() == DialogResult.OK)
            {
                dba.MySQLquery(@"UPDATE CLASSROOMS
                SET Number = '" + ChngClass.ClassNumberTextBox.Text + "', CTYPE = '"
                                 + ChngClass.idlist[ChngClass.ClassTypeComboBox.SelectedIndex] + "' WHERE ID ='"
                                 + dgvClassrooms.CurrentRow.Cells[0].Value.ToString() + "' ");

                DataSet ds5 = dba.FillGrid("SelectAllClassRooms", "ClassRooms");
                dgvClassrooms.DataSource = ds5.Tables["ClassRooms"].DefaultView;
            }
        }

        public void DeleteClassroomButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранную аудиторию?", "Предупреждение!",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM CLASSROOMS WHERE ID='"
                    + dgvClassrooms.CurrentRow.Cells[0].Value.ToString() + "'");
            }

            DataSet ds5 = dba.FillGrid("SelectAllClassRooms", "ClassRooms");
            dgvClassrooms.DataSource = ds5.Tables["ClassRooms"].DefaultView;
        }

        private void CreateNewLessonButton_Click(object sender, EventArgs e)
        {
            LessonCreationForm LCF = new LessonCreationForm();
            LCF.Show();
        }

        private void ViewLessonsListButton_Click(object sender, EventArgs e)
        {
            ViewLessonsForm VLF = new ViewLessonsForm();
            VLF.Show();
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////
        /// все что тебе нужно пиши далее
        /// 

        private void ScheduleDGV_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            enterfl = true;
            if ((e.Button == System.Windows.Forms.MouseButtons.Right) && (e.RowIndex >= 0) && (e.ColumnIndex >= 0))
            {
                flag = 1;
                rowIndex = e.RowIndex;
                colIndex = e.ColumnIndex;
                try
                {
                    ScheduleDGV.DoDragDrop(ScheduleDGV.Rows
                         [e.RowIndex].Cells[e.ColumnIndex].Value.ToString(),
                     DragDropEffects.Move);
                    //ScheduleDGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
                    //ScheduleDGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.SelectionBackColor = Color.Purple;
                    enterfl = true;
                }
                catch
                {

                }
                finally 
                { 

                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left && (e.RowIndex >= 0) && (e.ColumnIndex >= 0))
            {
                ScheduleDGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.SelectionBackColor = SystemColors.MenuHighlight;
                enterfl = false;
            }
        }

        private void ScheduleDGV_DragDrop(object sender, DragEventArgs e)
        {
            Point clientPoint1 = ScheduleDGV.PointToClient(new Point(e.X, e.Y));
            switch (flag)
            {
                case 1:
                    if (e.Data.GetDataPresent(typeof(System.String)))
                    {
                        Point clientPoint = ScheduleDGV.PointToClient(new Point(e.X, e.Y));

                        object startcell = (System.String)e.Data.GetData(typeof(System.String));

                        object tempcell = ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Value;


                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Value = startcell;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Selected = true;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Style.SelectionBackColor = Color.Purple;

                        ScheduleDGV.Rows[rowIndex].Cells[colIndex].Value = tempcell;

                        enterfl = false;
                    }
                    break;
                case 2:
                    if (e.Data.GetDataPresent(typeof(System.String)))
                    {
                        Point clientPoint = ScheduleDGV.PointToClient(new Point(e.X, e.Y));

                        object startcell = (System.String)e.Data.GetData(typeof(System.String));

                        object tempcell = ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Value;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint.X,
                           clientPoint.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint.X,
                        clientPoint.Y).ColumnIndex].Value = startcell;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint1.X,
                           clientPoint1.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint1.X,
                        clientPoint1.Y).ColumnIndex].Selected = true;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint1.X,
                           clientPoint1.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint1.X,
                        clientPoint1.Y).ColumnIndex].Style.SelectionBackColor = Color.DarkGoldenrod;

                        int tempindex = RightDGV.CurrentRow.Index;
                        //RightDGV.Rows[rowIndex].Cells[colIndex].Value = "";
                        RightDGV.Rows.RemoveAt(tempindex);
                        enterfl = false;
                    }
                    break;
                case 3:
                    if (e.Data.GetDataPresent(typeof(System.String)) && (ScheduleDGV.HitTest(clientPoint1.X, clientPoint1.Y).RowIndex >= 0) &&
                        (ScheduleDGV.HitTest(clientPoint1.X, clientPoint1.Y).ColumnIndex >= 0))
                    {
                        LimitationForm f = new LimitationForm();
                        f.Owner = this;
                        f.ShowDialog();
                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint1.X,
                           clientPoint1.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint1.X,
                        clientPoint1.Y).ColumnIndex].Value = (System.String)e.Data.GetData(typeof(System.String)) + " ауд." + classroom;
                        enterfl = false;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint1.X,
                           clientPoint1.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint1.X,
                        clientPoint1.Y).ColumnIndex].Selected = true;

                        ScheduleDGV.Rows[ScheduleDGV.HitTest(clientPoint1.X,
                           clientPoint1.Y).RowIndex].Cells[ScheduleDGV.HitTest(clientPoint1.X,
                        clientPoint1.Y).ColumnIndex].Style.SelectionBackColor = Color.DarkCyan;

                        

                    }
                    break;
            }
        }

        private void ScheduleDGV_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(System.String)))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }

        private void RightDGV_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if ((e.Button == System.Windows.Forms.MouseButtons.Left) && (e.RowIndex >= 0) && (e.ColumnIndex == 0))
            {
                flag = 2;
                RightDGV.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true;
                RightDGV.DoDragDrop(RightDGV.Rows
                       [e.RowIndex].Cells[e.ColumnIndex].Value.ToString(),
                DragDropEffects.Move);
                rowIndex = e.RowIndex;
                colIndex = e.ColumnIndex;
                enterfl = false;
            }

        }

        private void RightDGV_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(System.String)) && enterfl == true)
            {
                enterfl = false;
                RightDGV.Rows.Add((System.String)e.Data.GetData(typeof(System.String)));
                int tempindex = RightDGV.CurrentRow.Index;
                ScheduleDGV.Rows[rowIndex].Cells[colIndex].Value = "";
                
            }
        }

        private void RightDGV_DragEnter(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(System.String)))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }

        private void LeftDGV_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            enterfl = false;
            if ((e.Button == System.Windows.Forms.MouseButtons.Left) && (e.RowIndex >= 0) && (e.ColumnIndex >= 0))
            {
                flag = 3;
                LeftDGV.DoDragDrop(LeftDGV.Rows
                       [e.RowIndex].Cells[e.ColumnIndex].Value.ToString(),
                    DragDropEffects.Move);
            }
            
        }

        private void LeftDGV_DragEnter(object sender, DragEventArgs e)
        {

        }

        private void LeftDGV_DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(System.String)))
            {
                Point clientPoint = LeftDGV.PointToClient(new Point(e.X, e.Y));
                LeftDGV.Rows[LeftDGV.HitTest(clientPoint.X,
                   clientPoint.Y).RowIndex].Cells[LeftDGV.HitTest(clientPoint.X,
                clientPoint.Y).ColumnIndex].Value =
                   (System.String)e.Data.GetData(typeof(System.String));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LeftDGV.Refresh();
            ScheduleDGV.Refresh();
            RightDGV.Refresh();
        }

    }
}
